package com.qin.entity.subcomponents;

import com.qin.entity.ExecuteBean;
import com.qin.entity.ExecuteLog;
import com.qin.service.ExecuteService;
import com.qin.service.impl.ExecuteServiceImpl;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/*
 * 【子组件】生成日期
 */
public class DateSubComponent {

    //变量名
    private String date_paraname;
    //日期
    private String date_date;
    //日期格式
    private String date_format;

    private ExecuteService executeService = new ExecuteServiceImpl();

    public DateSubComponent(String date_paraname, String date_date, String date_format) {
        this.date_paraname = date_paraname;
        this.date_date = date_date;
        this.date_format = date_format;
    }

    public void execute(ExecuteBean executeBean){

        //设置ExecuteLog对象的各属性
        ExecuteLog executeLog = new ExecuteLog(executeBean.getExecute_id(), executeBean.getFunction_id(),
                executeBean.getTestcase_id(), executeBean.getComponent_id(), executeBean.getSubcomponent_id(), "");

        String date_paravalue = null;

        DateFormat dateFormat = new SimpleDateFormat(date_format);
        date_paravalue = dateFormat.format(new Date());

        Map<String, String> retMap = new HashMap();
        retMap.put(date_paraname, date_paravalue);

        //插入日志
        executeService.insertExecuteLog(executeLog, ">>>>>生成日期：变量名=" + date_paraname + "，变量值=" + date_paravalue);

        //把map的值添加到executeBean中
        executeBean.getParaMap().putAll(retMap);
    }

}
